package com.flyan.game.motafx.event;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.almasb.fxgl.dsl.components.EffectComponent;
import com.flyan.game.motafx.core.event.BaseEvent;
import com.flyan.game.motafx.core.event.enums.EventTypeEnum;
import com.flyan.game.motafx.core.util.core.GameUtils;
import com.flyan.game.motafx.core.util.cutscene.CutsceneUtils;
import com.flyan.game.motafx.effect.BaseEffect;

/**
 * 过场动画事件
 *
 * @author flyan
 * @version 1.0
 * @email flyan_by_chenu@sina.com
 * @since 2025/2/11
 */
public class CutsceneEvent extends BaseEvent {

    @Override
    public String type() {
        return EventTypeEnum.CUTSCENE.getCode();
    }

    @Override
    public void occur() {
        String cutsceneScript = properties.getStr("cutsceneScript");
        String cutsceneOnFinishCallbackEffect = properties.getStr("cutsceneOnFinishCallbackEffect");
        CutsceneUtils.startCutsceneByScript(cutsceneScript, () -> {
            /* 过场动画完成后回调效果 */
            if (StrUtil.isNotEmpty(cutsceneOnFinishCallbackEffect)) {
                BaseEffect effect = ReflectUtil.newInstance(cutsceneOnFinishCallbackEffect);
                GameUtils.app().braveEntityLv.get().getComponent(EffectComponent.class).startEffect(effect);
            }
        });
    }

}
